<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>角色管理</title>
  <jsp:include page="../../inc.jsp"></jsp:include>
  <%--<c:if test="${fn:contains(sessionInfo.resourceList, '/roleController/editPage')}">--%>
  <script type="text/javascript">
    $.canEdit = true;
  </script>
  <%--</c:if>--%>
  <%--<c:if test="${fn:contains(sessionInfo.resourceList, '/roleController/delete')}">--%>
  <script type="text/javascript">
    $.canDelete = true;
  </script>
  <%--</c:if>--%>
  <%--<c:if test="${fn:contains(sessionInfo.resourceList, '/roleController/grantPage')}">--%>
  <script type="text/javascript">
    $.canGrant = true;
  </script>
  <%--</c:if>--%>
  <script type="text/javascript">
    var dataGridRole;
    var initOptions;
    $(function () {
      initOptions = {
        ajaxUrl: '${pageContext.request.contextPath}/roleController/roleManage.html',
        idField: 'id',
        sortName: 'id',
        sortOrder: 'asc',
        checkOnSelect: false,
        selectOnCheck:false,
        frozenColumns: [[{
          title: '编号',
          field: 'id',
          width: 150
        }, {
          field: 'roleName',
          title: '角色名称',
          width: 150
        }]],
        columns: [[{
          field: 'roleInfo',
          title: '角色说明',
          width: 150
        }, {
          field: 'action',
          title: '操作',
          width: 200,
          formatter: function (value, row, index) {
            var str = '';
            if ($.canEdit) {
              str += $.formatString('<img onclick="editFunction(\'{0}\');" kk="{0}" src="{1}" title="编辑"/>', row.id, '${pageContext.request.contextPath}/resources/style/images/extjs_icons/pencil.png');
            }
            str += '&nbsp;';
            if ($.canGrant) {
              str += $.formatString('<img onclick="grantFunction(\'{0}\');" src="{1}" title="授权"/>', row.id, '${pageContext.request.contextPath}/resources/style/images/extjs_icons/key.png');
            }
            str += '&nbsp;';
            if ($.canDelete) {
              str += $.formatString('<img onclick="distributionFunction(\'{0}\');" src="{1}" title="分配员工"/>', row.id, '${pageContext.request.contextPath}/resources/style/images/extjs_icons/cup_key.png');
            }
            str += '&nbsp;';
            if ($.canDelete) {
              str += $.formatString('<img onclick="deleteFunction(\'{0}\');" src="{1}" title="删除"/>', row.id, '${pageContext.request.contextPath}/resources/style/images/extjs_icons/cancel.png');
            }
            return str;
          }
        }
        ]]
      }
      dataGridRole = initAjaxDataGrid("/roleController/roleManage.html", $('#dataGridRole'), initOptions);
    });

    function deleteFunction(id) {
      var ids=[];
      ids.push(id);
      deleteFun('您是否要删除当前角色？', '/roleController/deleteRole.html', $('#dataGridRole'), {"ids": ids});
    }

    function editFunction(id) {
      editFun('编辑角色', '/roleController/roleUpdate.html?id=',  $('#dataGridRole'), {"id": id});
    }

    function addFunction() {
      addFun("添加角色", "/roleController/roleAdd.html",  $('#dataGridRole'));
    }

    function grantFunction(id) {
      grantFun("角色授权", "/roleController/roleGrant.html?id=",  $('#dataGridRole'), {"id": id});
    }

    function distributionFunction(id){
      distributionFun("分配员工", "/roleController/distributeUser.html?id=", $('#dataGridRole'), {"id": id});
    }

    function refresh(){
      $('#dataGridRole').datagrid("reload");
//      initAjaxDataGrid("/roleController/roleManage.html", $('#dataGridRole'), initOptions)
    }


  </script>
</head>
<body>
<div class="easyui-layout" data-options="fit:true,border:false">
  <div data-options="region:'center',border:false" title="" style="overflow: hidden;">
    <table id="dataGridRole"></table>
  </div>
</div>
<div id="toolbar" style="display: none;">
  <%--<c:if test="${fn:contains(sessionInfo.resourceList, '/roleController/addPage')}">--%>
  <a onclick="addFunction();" href="javascript:void(0);" class="easyui-linkbutton"
     data-options="plain:true,iconCls:'style_add'">添加</a>
  <%--</c:if>--%>

  <a onclick="refresh()" href="javascript:void(0);" id="refreshNode" class="easyui-linkbutton"
     data-options="plain:true,iconCls:'transmit'">刷新</a>
</div>

<div id="menu" class="easyui-menu" style="width: 120px; display: none;">
  <%--<c:if test="${fn:contains(sessionInfo.resourceList, '/roleController/addPage')}">--%>
  <div onclick="addFunction();" data-options="iconCls:'style_add'">增加</div>
  <%--</c:if>--%>
  <%--<c:if test="${fn:contains(sessionInfo.resourceList, '/roleController/delete')}">--%>
  <div onclick="deleteFunction();" data-options="iconCls:'style_delete'">删除</div>
  <%--</c:if>--%>
  <%--<c:if test="${fn:contains(sessionInfo.resourceList, '/roleController/editPage')}">--%>
  <div onclick="editFunction();" data-options="iconCls:'style_edit'">编辑</div>
  <%--</c:if>--%>
</div>
</body>
</html>